import Vue from 'vue'
import Vuex from 'vuex'
import { loginapi } from '@/api'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import menu from './modules/menu'
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    token: localStorage.getItem('token') || ''
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token
      localStorage.setItem('token', token)
    }
  },
  actions: {
    async loginAciton(store, aaa) {
      const res = await loginapi(aaa)
      console.log(res.data.token);
      store.commit('SET_TOKEN', res.data.token)
      return res
    }
  },
  modules: {
    app,
    settings,
    menu,
  },
  getters
})

export default store